﻿@model Zatify.WebUI.Admin.Models.SendNewMessageViewModel
@{
    ViewBag.Title = "Message Center Compose";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}
<script type="text/javascript">

    registerValidator();

    function registerValidator() {

        $.validator.addMethod('requiredif',
            function (value, element, parameters) {
                var id = parameters['dependentproperty'];

                // get the target value (as a string, 
                // as that's what actual value will be)
                var targetvalue = parameters['targetvalue'];
                targetvalue = (targetvalue == null ? '' : targetvalue).toString();

                // get the actual value of the target control
                // note - this probably needs to cater for more 
                // control types, e.g. radios
                var control = $('input[id=' + id + ']:checked');

                var actualvalue = control.val();

                // if the condition is true, reuse the existing 
                // required field validator functionality
                if (targetvalue === actualvalue) {
                    return $.validator.methods.required.call(this, value, element, parameters);
                }

                return true;
            }
        );

        $.validator.unobtrusive.adapters.add(
        'requiredif',
        ['dependentproperty', 'targetvalue'],
        function (options) {
            options.rules['requiredif'] = {
                dependentproperty: options.params['dependentproperty'],
                targetvalue: options.params['targetvalue']
            };
            options.messages['requiredif'] = options.message;
        });
    }

    function messageUsersTypeChanged(e) {

        $("#IndividualUserId").val("");
    }

    $(document).ready(function () {

        var messageSubject = $("#Subject");
        var messageBody = $("#Body");
        var errorMessage = $("#errorMessage");

        $("#sendMessage").click(function (e) {

            //e.preventDefault();
        });

        $("#newMessageForm").submit(function () {
            if (!$(this).valid()) {

                var errorStr = "";
                errorMessage.show();

                if (messageSubject.hasClass("input-validation-error")) {
                    errorStr = messageSubject.data("valRequired");
                }

                if (messageBody.hasClass("input-validation-error")) {
                    errorStr += (errorStr) ? "<br/>" + messageBody.data("valRequired") : messageBody.data("valRequired");
                }

                errorMessage.html(errorStr);

                if (errorStr == "")
                    errorMessage.hide();

                return false;
            } else {

                errorMessage.hide();
            }
        });
    });

</script>
<!--start bradecums-->
<div class="bradecums_bar">
    Message Center <span>&raquo;</span> Compose
</div>
<!--end bradecums-->
<!--start button-->
<div class="zatify_panel_btn2 z_margin_bottom20px">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td>
                <a href="@Url.Action("Inbox", "MessageCenter")" style="text-decoration:none">
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Inbox" />
                </a><a href="@Url.Action("Outbox", "MessageCenter")" style="text-decoration:none">
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Outbox" />
                </a><a href="@Url.Action("Compose", "MessageCenter")" style="text-decoration: none">
                    <input name="" type="button" class="btn apps_btn apps_gray_btn" value="Compose" />
                </a>
            </td>
        </tr>
    </table>
    <div class="clearfix">
    </div>
</div>
<!--end button-->
<!--starts search results-->
<div class="search_result_bd">
    <!--<h4>Search Results</h4>-->
    <div class="z_message_conpose_bd">
        @using (Html.BeginForm("SendMessage", "MessageCenter", FormMethod.Post, new { id = "newMessageForm" }))
        {
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td class="message_to_row">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="10%">
                                    <h6>
                                        To:</h6>
                                </td>
                                <td>
                                    <label class="message_to">
                                        @Html.RadioButtonFor(m => m.SendingToUsersType, SendingToUsersType.AllUsers,
                 new { name = "sendingUsersType", @checked = (Model.SendingToUsersType == SendingToUsersType.AllUsers), onclick = "messageUsersTypeChanged(this)" })
                                        To all users</label>
                                    <label class="message_to">
                                        @Html.RadioButtonFor(m => m.SendingToUsersType, SendingToUsersType.BusinessUsers,
new { name = "sendingUsersType", @checked = (Model.SendingToUsersType == SendingToUsersType.BusinessUsers), onclick = "messageUsersTypeChanged(this)" })
                                        To all business users</label>
                                    <label class="message_to">
                                        @Html.RadioButtonFor(m => m.SendingToUsersType, SendingToUsersType.EndUsers,
new { name = "sendingUsersType", @checked = (Model.SendingToUsersType == SendingToUsersType.EndUsers), onclick = "messageUsersTypeChanged(this)" })
                                        To all end users</label>
                                    <label class="message_to">
                                        @Html.RadioButtonFor(m => m.SendingToUsersType, SendingToUsersType.IndividualUser,
                                        new { name = "sendingUsersType", @checked = true })
                                        To an individual users</label>
                                    @Html.TextBoxFor(m => m.IndividualUserId, new { @class = "apps_inputbox" }) @Html.ValidationMessageFor(m => m.IndividualUserId)
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td class="message_subject_row">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="10%">
                                    <h6>
                                        Subject:</h6>
                                </td>
                                <td>
                                    @*<input type="text" value="" name="Name" class="compose_sub_inputbox">*@
                                    @Html.TextBoxFor(m => m.Subject, new { @class = "compose_sub_inputbox" })
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="z_messages_area">
                            @*<textarea class="z_messages_box_full"> </textarea>*@
                            @Html.TextAreaFor(m => m.Body, new { @class = "z_messages_box_full" })
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="zatify_panel_btn">
                            <input id="sendMessage" name="" type="submit" class="btn apps_btn apps_gray_btn"
                                value="Send" />
                        </div>
                        <div id="errorMessage" class="error_message" style="display: none;">
                            @Html.ValidationMessageFor(m => m.IndividualUserId)
                        </div>
                    </td>
                </tr>
            </table>
        }
    </div>
</div>
<div class="clearfix">
</div>
<!--end search results-->
